import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore('adminUser', () => {
  const userInfo = ref(null)
  const token = ref(localStorage.getItem('admin_token') || '')
  
  function setUserInfo(info) {
    userInfo.value = info
  }
  
  function setToken(newToken) {
    token.value = newToken
    localStorage.setItem('admin_token', newToken)
  }
  
  function logout() {
    userInfo.value = null
    token.value = ''
    localStorage.removeItem('admin_token')
  }
  
  return {
    userInfo,
    token,
    setUserInfo,
    setToken,
    logout
  }
})